#include "chatmessagetoclient.h"


ChatMessageToClient::ChatMessageToClient(const SenderId& senderId, const ChatMessage& chatMsg,
                    const CreateTime& sendTime, const int& id)
{
    m_messageType = MessageType::ChatMessageToClient;
    m_senderId = senderId;
    m_chatMessage = chatMsg;
    m_sendTime = sendTime;
    m_id = id;
}

ChatMessageToClient::ChatMessageToClient(const QJsonObject& jsonObj)
{
    m_messageType = static_cast<MessageType>(jsonObj[JsonKey::TYPE].toInt());
    m_senderId = jsonObj[JsonKey::SENDER_ID].toString();
    m_chatMessage = jsonObj[JsonKey::CHAT_MSG].toString();
    m_sendTime = jsonObj[JsonKey::CREATE_TIME].toString();
    m_id = jsonObj[JsonKey::ID].toInt();
}

QJsonObject ChatMessageToClient::PackJsonData() const
{
    QJsonObject jsonObj;
    jsonObj[JsonKey::TYPE] = static_cast<int>(m_messageType);
    jsonObj[JsonKey::SENDER_ID] = m_senderId;
    jsonObj[JsonKey::CHAT_MSG] = m_chatMessage;
    jsonObj[JsonKey::CREATE_TIME] = m_sendTime;
    jsonObj[JsonKey::ID] = m_id;
    return jsonObj;
}

SenderId ChatMessageToClient::getSenderId() const
{
    return m_senderId;
}

ChatMessage ChatMessageToClient::getChatMessage() const
{
    return m_chatMessage;
}

CreateTime ChatMessageToClient::getSendTime() const
{
    return m_sendTime;
}

Id ChatMessageToClient::getId() const
{
    return m_id;
}
